import request from '@/sheep/request';

const BuddyApi = {
  // 获取所有搭子类型列表
  getBuddyTypeList: () => {
    return request({
      url: '/member/buddy-type/list',
      method: 'GET',
      custom: {
        showLoading: false,
        showError: true,
        auth: false,
      },
    });
  },
  // 创建搭子订单（发布搭子）
  createBuddyOrder: (data) => {
    return request({
      url: '/member/buddy-order/create',
      method: 'POST',
      data,
      custom: {
        showLoading: true,
        showError: true,
      },
    });
  },
  // 获取搭子订单分页列表
  getBuddyOrderPage: (params) => {
    return request({
      url: '/member/buddy-order/page',
      method: 'GET',
      params,
      custom: {
        showLoading: false,
        showError: true,
      },
    });
  },
  // 获取搭子订单详情
  getBuddyOrderDetail: (id) => {
    return request({
      url: `/member/buddy-order/${id}`,
      method: 'GET',
      custom: {
        showLoading: true,
        showError: true,
      },
    });
  },
  // 获取我发布的搭子订单
  getMyPublishedOrders: (params) => {
    return request({
      url: '/member/buddy-order/my/published',
      method: 'GET',
      params,
      custom: {
        showLoading: false,
        showError: true,
      },
    });
  },
  // 获取我参与的搭子订单
  getMyAcceptedOrders: (params) => {
    return request({
      url: '/member/buddy-order/my/accepted',
      method: 'GET',
      params,
      custom: {
        showLoading: false,
        showError: true,
      },
    });
  },
  // 接受搭子订单
  acceptBuddyOrder: (data) => {
    return request({
      url: '/member/buddy-order/accept',
      method: 'POST',
      data,
      custom: {
        showLoading: true,
        showError: true,
      },
    });
  },
  // 取消搭子订单
  cancelBuddyOrder: (id) => {
    return request({
      url: `/member/buddy-order/cancel/${id}`,
      method: 'POST',
      custom: {
        showLoading: true,
        showError: true,
      },
    });
  },
  // 确认接单人
  confirmAccepter: (orderId, accepterId) => {
    return request({
      url: `/member/buddy-order/confirm/${orderId}/${accepterId}`,
      method: 'POST',
      custom: {
        showLoading: true,
        showError: true,
      },
    });
  },
  // 拒绝接单人
  rejectAccepter: (orderId, accepterId) => {
    return request({
      url: `/member/buddy-order/reject/${orderId}/${accepterId}`,
      method: 'POST',
      custom: {
        showLoading: true,
        showError: true,
      },
    });
  },
  // 确认我参与的订单（参与者确认订单完成）
  confirmParticipatedOrder: (acceptId, needConfirm, longitude, latitude) => {
    const data = { acceptId }
    if (needConfirm && longitude !== undefined && latitude !== undefined) {
      data.longitude = longitude
      data.latitude = latitude
    }
    return request({
      url: `/member/buddy-order/accept/confirm`,
      method: 'POST',
      data,
      custom: {
        showLoading: true,
        showError: true,
      },
    });
  },
  // 取消我参与的订单（参与者取消接单）
  cancelAcceptedOrder: (id) => {
    return request({
      url: `/member/buddy-order/accept/cancel/${id}`,
      method: 'POST',
      custom: {
        showLoading: true,
        showError: true,
      },
    });
  },
  // 获取指定用户参与的搭子订单
  getUserAcceptedOrders: (userId, params) => {
    return request({
      url: `/member/buddy-order/user/${userId}/accepted`,
      method: 'GET',
      params,
      custom: {
        showLoading: false,
        showError: true,
      },
    });
  },
  // 提交评价
  submitReview: (data) => {
    return request({
      url: '/member/buddy-order/review',
      method: 'POST',
      data,
      custom: {
        showLoading: true,
        showError: true,
      },
    });
  },
};

export default BuddyApi;

